﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;
using System.Data;

namespace DAL
{
    public class DBranch : BaseProvider
    {
        public void InsertBranch(string sBranchName)
        {
            try
            {

                string sSQLCommand = "insert into T_BRANCH values(@name,@address)";
                DbCommand cmd = Provider.GetSqlStringCommand(sSQLCommand);

                Provider.AddInParameter(cmd, "@name", SqlDbType.NVarChar, sBranchName);
                Provider.AddInParameter(cmd, "@address", SqlDbType.NVarChar, sBranchName);

                Provider.ExecuteNonQuery(cmd);

                
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                
            }
        }

        public DataSet GetAllBranch()
        { 
            DataSet ds = new DataSet();
            try
            {
               
                string sSQLCommand = "select * from T_BRANCH";
                DbCommand cmd = Provider.GetSqlStringCommand(sSQLCommand);
                ds = Provider.ExecuteDataSet(cmd);

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            { 

            }
            return ds;
        }

        public bool IsExistBranch(string sBranchName)
        {
            bool bRes = false;
            try
            {
                string sSQLCommand = "select count(1) from T_BRANCH where BranchName=@name";
                DbCommand cmd = Provider.GetSqlStringCommand(sSQLCommand);
                Provider.AddInParameter(cmd, "@name", SqlDbType.NVarChar, sBranchName);
                bRes = Convert.ToInt32(Provider.ExecuteScalar(cmd))>0?true:false;

            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            { 

            }
            return bRes;
        }

       
    }
}
